package com.combining.b_adapter.main;

import com.combining.b_adapter.Goose;
import com.combining.b_adapter.face.Quackable;
import com.combining.b_adapter.impl.DuckCall;
import com.combining.b_adapter.impl.GooseAdapter;
import com.combining.b_adapter.impl.MallardDuck;
import com.combining.b_adapter.impl.RedheadDuck;
import com.combining.b_adapter.impl.RubberDuck;

/**
 * 我们想要在使用鸭子的地方使用鹅，毕竟鹅会叫、会飞、会游泳，和鸭子差不多。所以我们用适配器把鸭子和鹅掺杂在一起
 * 
 * @author dell
 * 
 */
// 有一只鹅出现了，它希望自己像一个Quackable，所以利用适配器模式，将鹅适配成Quackable。
public class DuckSimulator {
	public static void main(String[] args) {
		DuckSimulator simulator = new DuckSimulator();
		simulator.simulate();
	}

	void simulate() {
		Quackable mallardDuck = new MallardDuck();
		Quackable redheadDuck = new RedheadDuck();
		Quackable duckCall = new DuckCall();
		Quackable rubberDuck = new RubberDuck();
		Quackable gooseDuck = new GooseAdapter(new Goose());

		System.out.println("\n鸭子模拟器，和鹅适配器：");

		simulate(mallardDuck);
		simulate(redheadDuck);
		simulate(duckCall);
		simulate(rubberDuck);
		simulate(gooseDuck);
	}

	void simulate(Quackable duck) {
		duck.quack();
	}
}
